package util;

import config.Commodity;
import config.People;

import javax.swing.*;
import java.math.BigDecimal;

/**
 * @author admin
 */
public class GameUtil {
    /**
     * 当前游戏天数
     */
    private static int day;

    /**
     * 当前所在地
     */
    private static String city;

    private static boolean flag = true;

    public static int getDay() {
        return day;
    }

    public static void setDay(int day) {
        GameUtil.day = day;
    }

    public static String getCity() {
        return city;
    }

    public static void setCity(String city) {
        GameUtil.city = city;
    }

    /**
     * 下一天,天數加一,金钱减五,市场价格重随,自动保存
     */
    public static void nextDay() {
        day++;
        People.setMoney(People.getMoney().subtract(new BigDecimal(5)));
        Commodity.randPrice();
        save();

        if (People.getMoney().floatValue() < 0){
            //第一次负数
            if (flag){
                flag = false;
                JOptionPane.showMessageDialog(null,"您当前资产为负数,请注意","错误 ",0);
            }else {
                JOptionPane.showMessageDialog(null,"您被饿死了","错误 ",0);
                System.exit(0);
            }
        }else {
            flag = true;
        }
    }

    /**
     * 保存
     */
    public static void save() {
        System.out.println("保存");
    }

}
